﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Gunningine
{
    public static class MathsUtils
    {
        public const float Pi = 3.14159265f;

        /// <summary>
        /// Convert a value in degrees to radians.
        /// </summary>
        /// <param name="degrees"></param>
        /// <returns></returns>
        public static float DegToRad(float degrees)
        {
            return degrees * Pi / 180.0f;
        }

        /// <summary>
        /// Convert a value in radians to degrees.
        /// </summary>
        /// <param name="radians"></param>
        /// <returns></returns>
        public static float RadToDeg(float radians)
        {
            return radians * 180.0f / Pi;
        }

        /// <summary>
        /// Convert a value in degrees to radians.
        /// </summary>
        /// <param name="degrees"></param>
        /// <returns></returns>
        public static float DegToRad(double degrees)
        {
            return (float)(degrees * Pi / 180.0);
        }

        /// <summary>
        /// Convert a value in radians to degrees.
        /// </summary>
        /// <param name="radians"></param>
        /// <returns></returns>
        public static float RadToDeg(double radians)
        {
            return (float)(radians * 180.0 / Pi);
        }

        public static int NextPow2(int value)
        {
            value--;

            value |= value >> 1;
            value |= value >> 2;
            value |= value >> 4;
            value |= value >> 8;
            value |= value >> 16;

            value++;
            return value;
        }
    }
}
